using UnityEngine;
using UnityEngine.EventSystems;

namespace MaterialUI
{
	public class DragEventSender : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IEventSystemHandler
	{
		[SerializeField]
		private GameObject m_HorizontalTargetObject;

		[SerializeField]
		private GameObject m_LeftTargetObject;

		[SerializeField]
		private GameObject m_RightTargetObject;

		[SerializeField]
		private GameObject m_VerticalTargetObject;

		[SerializeField]
		private GameObject m_UpTargetObject;

		[SerializeField]
		private GameObject m_DownTargetObject;

		[SerializeField]
		private GameObject m_AnyDirectionTargetObject;

		private bool m_CurrentDragIsHorizontal;

		private bool m_CurrentDragIsLeft;

		private bool m_CurrentDragIsUp;

		[SerializeField]
		private bool m_CombineLeftAndRight = true;

		[SerializeField]
		private bool m_CombineUpAndDown = true;

		public GameObject horizontalTargetObject
		{
			get
			{
				return m_HorizontalTargetObject;
			}
			set
			{
				m_HorizontalTargetObject = value;
			}
		}

		public GameObject leftTargetObject
		{
			get
			{
				return m_LeftTargetObject;
			}
			set
			{
				m_LeftTargetObject = value;
			}
		}

		public GameObject rightTargetObject
		{
			get
			{
				return m_RightTargetObject;
			}
			set
			{
				m_RightTargetObject = value;
			}
		}

		public GameObject verticalTargetObject
		{
			get
			{
				return m_VerticalTargetObject;
			}
			set
			{
				m_VerticalTargetObject = value;
			}
		}

		public GameObject upTargetObject
		{
			get
			{
				return m_UpTargetObject;
			}
			set
			{
				m_UpTargetObject = value;
			}
		}

		public GameObject downTargetObject
		{
			get
			{
				return m_DownTargetObject;
			}
			set
			{
				m_DownTargetObject = value;
			}
		}

		public GameObject anyDirectionTargetObject
		{
			get
			{
				return m_AnyDirectionTargetObject;
			}
			set
			{
				m_AnyDirectionTargetObject = value;
			}
		}

		public bool combineLeftAndRight
		{
			get
			{
				return m_CombineLeftAndRight;
			}
			set
			{
				m_CombineLeftAndRight = value;
			}
		}

		public bool combineUpAndDown
		{
			get
			{
				return m_CombineUpAndDown;
			}
			set
			{
				m_CombineUpAndDown = value;
			}
		}

		public void OnDrag(PointerEventData eventData)
		{
			if (m_CurrentDragIsHorizontal)
			{
				if (m_CombineLeftAndRight)
				{
					if (m_HorizontalTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_HorizontalTargetObject, eventData, ExecuteEvents.dragHandler);
					}
				}
				else
				{
					Vector2 delta = eventData.delta;
					m_CurrentDragIsLeft = (delta.x < 0f);
					if (m_CurrentDragIsLeft)
					{
						if (m_LeftTargetObject != null)
						{
							ExecuteEvents.ExecuteHierarchy(m_LeftTargetObject, eventData, ExecuteEvents.dragHandler);
						}
					}
					else if (m_RightTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_RightTargetObject, eventData, ExecuteEvents.dragHandler);
					}
				}
			}
			else if (m_CombineUpAndDown)
			{
				if (m_VerticalTargetObject != null)
				{
					ExecuteEvents.ExecuteHierarchy(m_VerticalTargetObject, eventData, ExecuteEvents.dragHandler);
				}
			}
			else
			{
				Vector2 delta2 = eventData.delta;
				m_CurrentDragIsUp = (delta2.y > 0f);
				if (m_CurrentDragIsUp)
				{
					if (m_UpTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_UpTargetObject, eventData, ExecuteEvents.dragHandler);
					}
				}
				else if (m_DownTargetObject != null)
				{
					ExecuteEvents.ExecuteHierarchy(m_DownTargetObject, eventData, ExecuteEvents.dragHandler);
				}
			}
			if (m_AnyDirectionTargetObject != null)
			{
				ExecuteEvents.ExecuteHierarchy(m_AnyDirectionTargetObject, eventData, ExecuteEvents.dragHandler);
			}
		}

		public void OnBeginDrag(PointerEventData eventData)
		{
			Vector2 delta = eventData.delta;
			float num = Mathf.Abs(delta.x);
			Vector2 delta2 = eventData.delta;
			m_CurrentDragIsHorizontal = (num > Mathf.Abs(delta2.y));
			if (m_CurrentDragIsHorizontal)
			{
				if (m_CombineLeftAndRight)
				{
					if (m_HorizontalTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_HorizontalTargetObject, eventData, ExecuteEvents.beginDragHandler);
					}
				}
				else
				{
					Vector2 delta3 = eventData.delta;
					m_CurrentDragIsLeft = (delta3.x < 0f);
					if (m_CurrentDragIsLeft)
					{
						if (m_LeftTargetObject != null)
						{
							ExecuteEvents.ExecuteHierarchy(m_LeftTargetObject, eventData, ExecuteEvents.beginDragHandler);
						}
					}
					else if (m_RightTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_RightTargetObject, eventData, ExecuteEvents.beginDragHandler);
					}
				}
			}
			else if (m_CombineUpAndDown)
			{
				if (m_VerticalTargetObject != null)
				{
					ExecuteEvents.ExecuteHierarchy(m_VerticalTargetObject, eventData, ExecuteEvents.beginDragHandler);
				}
			}
			else
			{
				Vector2 delta4 = eventData.delta;
				m_CurrentDragIsUp = (delta4.y > 0f);
				if (m_CurrentDragIsUp)
				{
					if (m_UpTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_UpTargetObject, eventData, ExecuteEvents.beginDragHandler);
					}
				}
				else if (m_DownTargetObject != null)
				{
					ExecuteEvents.ExecuteHierarchy(m_DownTargetObject, eventData, ExecuteEvents.beginDragHandler);
				}
			}
			if (m_AnyDirectionTargetObject != null)
			{
				ExecuteEvents.ExecuteHierarchy(m_AnyDirectionTargetObject, eventData, ExecuteEvents.beginDragHandler);
			}
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			if (m_CurrentDragIsHorizontal)
			{
				if (m_CombineLeftAndRight)
				{
					if (m_HorizontalTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_HorizontalTargetObject, eventData, ExecuteEvents.endDragHandler);
					}
				}
				else
				{
					Vector2 delta = eventData.delta;
					m_CurrentDragIsLeft = (delta.x < 0f);
					if (m_CurrentDragIsLeft)
					{
						if (m_LeftTargetObject != null)
						{
							ExecuteEvents.ExecuteHierarchy(m_LeftTargetObject, eventData, ExecuteEvents.endDragHandler);
						}
					}
					else if (m_RightTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_RightTargetObject, eventData, ExecuteEvents.endDragHandler);
					}
				}
			}
			else if (m_CombineUpAndDown)
			{
				if (m_VerticalTargetObject != null)
				{
					ExecuteEvents.ExecuteHierarchy(m_VerticalTargetObject, eventData, ExecuteEvents.endDragHandler);
				}
			}
			else
			{
				Vector2 delta2 = eventData.delta;
				m_CurrentDragIsUp = (delta2.y > 0f);
				if (m_CurrentDragIsUp)
				{
					if (m_UpTargetObject != null)
					{
						ExecuteEvents.ExecuteHierarchy(m_UpTargetObject, eventData, ExecuteEvents.endDragHandler);
					}
				}
				else if (m_DownTargetObject != null)
				{
					ExecuteEvents.ExecuteHierarchy(m_DownTargetObject, eventData, ExecuteEvents.endDragHandler);
				}
			}
			if (m_AnyDirectionTargetObject != null)
			{
				ExecuteEvents.ExecuteHierarchy(m_AnyDirectionTargetObject, eventData, ExecuteEvents.endDragHandler);
			}
		}
	}
}
